package com.cykj.pos.controller.api;

import com.cykj.common.core.domain.AjaxResult;
import com.cykj.pos.domain.BizPosMachine;
import com.cykj.pos.profit.dto.MerchantsTransferDTO;
import com.cykj.pos.service.IBizAllocAdjRecordsService;
import com.cykj.pos.service.IBizMerchantService;
import com.cykj.pos.service.IBizPosMachineService;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/pos/api/v2/transfer")
public class PosV2AppMerchantsTransferController {

    private final IBizMerchantService merchantService;

    private final IBizPosMachineService posMachineService;

    private final IBizAllocAdjRecordsService allocAdjRecordsService;

    @ApiOperation(value = "获取商户转移列表")
    @ApiResponses({@ApiResponse(code = 200, response = BizPosMachine.class, message = "获取当前用户商户转移列表数据响应成功"),})
    @PostMapping("/list")
    public AjaxResult queryMerchantsTransferList(@RequestBody MerchantsTransferDTO merchantsTransferDTO) {
        AjaxResult ajaxResult = AjaxResult.success();
        String nickName = merchantsTransferDTO.getNickName();
        List<MerchantsTransferDTO> transferList =posMachineService.getAllMerchantByNickName(nickName);
        ajaxResult.put("data", transferList);
        return ajaxResult;
    }
    @ApiOperation(value = "商户转移")
    @ApiResponses({@ApiResponse(code = 200, response = BizPosMachine.class, message = "数据响应成功"),})
    @PostMapping("/updateTransfer")
    public AjaxResult updateMerchantsTransfer(@RequestBody BizPosMachine bizPosMachine) {
        AjaxResult ajaxResult = AjaxResult.success();
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        simpleDateFormat.format(date);
        bizPosMachine.setUpdateTime(date);
        BizPosMachine bizPos=posMachineService.getPosMachineBySnCode(bizPosMachine.getPosCode());
        bizPosMachine.setVar3(String.valueOf(bizPos.getMerchId()));
        posMachineService.updateMerchantsTransfer(bizPosMachine);
        ajaxResult.put("data", "转移成功");
        return ajaxResult;
    }


}
